
package com.example.caorl.job5thread.interrupt;

import java.io.IOException;

public class RunnerMain {

    public static void main(String[] args) throws IOException, InterruptedException {

        Runner1 runner1 = new Runner1();
        Thread thread1 = new Thread(runner1, "my-thread-1");

        Runner2 runner2 = new Runner2();
        Thread thread2 = new Thread(runner2, "my-thread-2");

        thread1.start();
//        thread2.start();

        Thread.sleep(100);
//        System.out.println("==============开始中断线程");
        System.out.println("=============暂停thread1");
//        thread1.wait(); //这个也会触发线程内部的run方法里的睡眠.wait是Object的方法，不会终端线程
        /*thread1.join(); //join是挂起当前线程，先运行子线程，等待子线程运行完毕
        Thread.sleep(3000);
        System.out.println("==============继续thread1===========================================================");
        thread1.notify();*/

        thread1.interrupt(); //无法打断Runner1循环中catch了InterruptedException的循环

//        thread2.interrupt();  // i = true

        System.out.println("activeCount:"+Thread.activeCount());
        System.out.println("分割线--------------------------------");
        System.out.println(Thread.currentThread().getThreadGroup().getParent().activeGroupCount());
        Thread.currentThread().getThreadGroup().list();
        System.out.println("分割线+++++++++++++++++");
        System.out.println(Thread.currentThread().getThreadGroup().getParent().activeGroupCount());
        System.out.println("分割线================");
        Thread.currentThread().getThreadGroup().getParent().list();
    
        
    }
}
